<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <!-- 给HTML标签设置ref属性 -->
    <input type="input" ref="inp">
    <button @click="fn">点我获取焦点</button>
    <!-- 给子组件设置ref属性 -->
    <com-a ref="comA"></com-a>
  </div>
</body>
<script src="./lib/vue.js"></script>
<script>
  var ComA = {
    template: `<div>组件A的内容:{{value}}</div>`,
    data(){
      return {
        value: '实例内容'
      }
    }
  }
  var myApp = new Vue({
    el: "#app",
    methods: {
      fn(){
        this.$refs.inp.focus();
        this.$refs.comA.value = '我是新的内容'
      }
    },
    components: {
      ComA
    },
    mounted() {
      this.$refs.comA.value = '123'
    }
  })
</script>
</html>